package cn.springboot.chapter05mybaits.controller;

import cn.springboot.chapter05mybaits.beans.*;
import cn.springboot.chapter05mybaits.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BookController {
    @Autowired
    private BookSerivce bookSerivce;
    @GetMapping("/bookOps")
    public  void bookOps(){
        Book b1=new Book();
        b1.setName("西厢记");
        b1.setAuthor("王实甫");
        int i=bookSerivce.addBook(b1);
        System.out.println("addBook>>"+i);
        Book b2=new Book();
        b2.setId(1);
        b2.setName("朝花夕拾");
        b2.setAuthor("鲁迅");
        int updateBook=bookSerivce.updateBook(b2);
        System.out.println("updateBook>>"+updateBook);
        Book b3=bookSerivce.getBookById(1);
        System.out.println("getBookById>>"+b3);
        int delte=bookSerivce.deleteBook(2);
        System.out.println("deleteBook>>"+delte);
        List<Book> allBooks=bookSerivce.getAllBooks();
        System.out.println("getAllBooks>>"+allBooks);
    }

}
